<!--# layout("/common/layout.html",{"jsBase":"/js/promote/templateShare/"}){ -->

<form class="layui-form layui-form-pane" id="addForm" enctype="multipart/form-data" lay-filter="editform">
    <input type="hidden" name="templateId" id="templateId">

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">模板名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="templateName" id="templateName" autocomplete="off" class="layui-input"
                           lay-verify="required" maxlength="20">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">模板标题</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" id="title" autocomplete="off" class="layui-input"
                           lay-verify="required" maxlength="20">
                </div>
            </div>
        </div><!--form item-->
    </div><!--row-->
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">

                <layui:image id="imgUrl" tagName="图片" tips="尺寸:200*200"/>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">内容</label>
                <div class="layui-input-block" style="width:512px">
                    <textarea name="templateDesc" id="templateDesc" maxlength="500" placeholder="请输入不超过500字" class="layui-textarea"></textarea>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">短信模板</label>
                <div class="layui-input-block" style="width:512px">
                    <textarea name="smsTemplate" id="smsTemplate" maxlength="200" placeholder="请输入不超过200字" class="layui-textarea"></textarea>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <layui:image id="poster" tagName="海报图" tips="尺寸:540*708"/>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">可用标记</label>
                <div class="layui-input-inline">
                    <input type="radio" name="templateStatus" value="1" title="是">
                    <input type="radio" name="templateStatus" value="0" title="否">

                </div>
            </div>
        </div>
    </div>
    <layui:submitButtons id="addButton"/>
</form>
<!--#} -->
<script>
    Common.initImage();
    layui.define(['form', 'laydate', 'table', 'templateShareApi'], function (exports) {
        var form = layui.form;
        var templateShareApi = layui.templateShareApi;
        var index = layui.index;
        var isNew = true;
        <!--# if(!(isEmpty(templateShareJson))){  -->
        isNew = false;
        <!--# } -->
        var view = {
            init: function () {
                Lib.initGenrealForm($("#addForm"), form);
                this.initSubmit();
            },
            initSubmit: function () {
                $("#addButton").click(function () {
                    form.on('submit(form)', function () {
                        templateShareApi.saveForm(isNew, $('#addForm'), function () {
                            parent.window.dataReload();
                            Common.info("保存成功");
                            Lib.closeFrame();
                        });
                    });
                });

                $("#addButton-cancel").click(function () {
                    Lib.closeFrame();
                });
            }

        }
        view.init();
        <!--# if(!(isEmpty(templateShareJson))){  -->
        var formJson = ${templateShareJson};
        form.val("editform", formJson);
        $(".image-preview").each(function () {
            $(this).attr("src", formJson[$(this).attr("id")]);
        });
        <!--# } -->
    });
</script>
